package com.gzrobot.webCapTest.config;

import cn.hutool.core.thread.NamedThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
* 
* @author : Cmy
* @date : 2025-05-22 16:56
*/
@Configuration
public class ThreadPoolConfig {

    @Bean("captureThreadPool")
    public ThreadPoolExecutor threadPoolExecutor() {
        int corePoolSize = Math.max(1, Runtime.getRuntime().availableProcessors() / 2);
        int maxPoolSize = corePoolSize+1;
        return new ThreadPoolExecutor(
                corePoolSize,
                maxPoolSize,
                60,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(50000),//允许排队50000张图片 thumbnail 处理1000张 大概需要 10-20s 10000 -> 200s
                new NamedThreadFactory("webCapture", false),
                new ThreadPoolExecutor.AbortPolicy());
    }

}

    